package com.rd.student.jiaji.class2.shirui.exam0808.prac2;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class TestTeam {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        try {

            BufferedReader reader = new BufferedReader(new FileReader("player.txt"));

            Map<String, String> playerMap = new HashMap<>();

            String line;
            while ((line = reader.readLine()) != null) {

                String[] players = line.split(",");

                if (players.length == 2) {
                    String player = players[0].trim();
                    String team = players[1].trim();
                    playerMap.put(player, team);
                }
            }

            System.out.print("请输入球员名字：");
            String playerName = scanner.nextLine();

            String teamName = playerMap.get(playerName);
            if (teamName != null) {
                System.out.println("该球员所属球队：" + teamName);
            } else {
                System.out.println("不存在该球员！");
            }

            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
